﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

namespace Sino.CapacityCloud.WebApi
{
    
    public class UsersResponse
    {
        public int total { get; set; }
        public IEnumerable<User> list { get; set; }
    }

    public class User
    {
        public int index { get; set; }
        public string userId { get; set; }
        public CertificationStatus realNameState { get; set; }
        public string realName { get; set; }
        public string phoneNumber { get; set; }
        public string isLockedout { get; set; }
        public DateTime certificationTime { get; set; }
        public string carLength { get; set; }
        public string userName { get; set; }
        public string carType { get; set; }
        public string roles { get; set; }
        public string carNumber { get; set; }

    }
    public class UsersDetailResponse
    {
        public string carCode { get; set; }
        public string drivingLicenseImage { get; set; }
        public int drivingLicenseState { get; set; }
        public string idCardImage { get; set; }
        public int idCardState { get; set; }
        public string message { get; set; }
        public string realHeadImage { get; set; }
        public int realHeadState { get; set; }
        public int state { get; set; }
        public string vehicleLicenseImage { get; set; }
        public int vehicleLicenseState { get; set; }
    }


    public class TagsResponse
    {
        public string Error { get; set; }
        public TagResponse Response { get; set; }
    }
    public class TagResponse
    {

    }
    //public class putUserStatus
    //{
    //    public string carCode { get; set; }
    //    public int drivingLicenseKeyStatus { get; set; }
    //    public int idCardKeyStatus { get; set; }
    //    public string message { get; set; }
    //    public int realHeadKeyStatus { get; set; }
    //    public int vehicleLicensekeyStatus { get; set; }
    //}
    public class UsersEditResponse
    {
        public string Error { get; set; }
        public UserEditResponse Response { get; set; }
    }
    public class UserEditResponse
    {
    }

    public class UsersController : Controller
    {

        private readonly IUserService _userService;

        public UsersController(IUserService userService)
        {
            this._userService = userService;
        }

        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="carCode"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="roleId"></param>
        /// <param name="state"></param>
        /// <param name="useCache"></param>
        /// <param name="startIndex"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        [HttpGet("users")]
        public async Task<JsonResult> users(string keyword, string carCode, DateTime? startTime, DateTime? endTime, string roleId, CertificationStatus state, bool useCache = true, int startIndex = 0, int count = 10)
        {
            var response = await this._userService.GetUsersListAsync(keyword, carCode, startTime, endTime, roleId, state, useCache, startIndex, count);
            return Json(response, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
        }

        //获取用户详情
        [HttpGet("users/{user_id}")]
        public async Task<JsonResult> getDetail(string user_id)
        {
            var response = await this._userService.GetUserDetailAsync(user_id);
            return Json(response, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
        }

        //启用禁用
        [HttpGet("users/{user_id}/enabled")]
        public async Task<JsonResult> SetAccountLockoutState(string user_id, bool disabled)
        {
            var response = await this._userService.SetAccountLockoutStateAsync(user_id, disabled);
            return Json(response, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
        }
        //编辑用户实名认证状态
        [HttpPut("users/{user_id}")]
        public async Task<JsonResult> putUserRealNameCertificationStatus(string user_id, [FromBody] UserStatusEdit putUserStatus)
        {
            var response = await this._userService.UpdateUserStatusAsync(user_id, putUserStatus);
            return Json(response, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
        }
    }
}
